package com.eos.control.action.customer;

import java.util.List;

import com.eos.business.service.SysProductBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.ProductBrand;
import com.eos.orm.mybatis.model.SysUser;
import com.hf.utils.StringUtil;

public class SaveBrandAction extends AbstractBaseAction {
	private static final long serialVersionUID = 5186474619277066032L;
	private Integer productId;
	private String brandName;
	private String brandDesc;
	
	
    public void setProductId(Integer productId) {
		this.productId = productId;
	}

	public void setBrandName(String brandName) {
		this.brandName = brandName;
	}
	
	public void setBrandDesc(String brandDesc) {
		this.brandDesc = brandDesc;
	}

	@Override
	public String execute() {
		try{
			if(StringUtil.isEmpty(brandName)){
				statusCode = "300";
				message = "请输入品牌名称!";
			}else{
				ProductBrand brand = new ProductBrand();
				brand.setBrandName(brandName);
				brand.setDealFlag(ConstantTool.DEAL_FALG_OK);
				brand.setStatus(ConstantTool.STATUS_OK);
				SysProductBusinessService spbs = new SysProductBusinessService();
				List<ProductBrand> brandList = spbs.getProductBrandExample(brand);
				if(null != brandList && brandList.size() >0){
					statusCode = "300";
					message = "输入的品牌已经存在, 保存失败!";
				}else{
					String strTime = ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss");
					SysUser user = (SysUser) getSession().getAttribute("SysUser");
					String userId = user.getId()+"";
					brand.setBrandDesc(brandDesc);
					brand.setInsertTime(strTime);
					brand.setInsertUserId(userId);
					brand.setModifyTime(strTime);
					brand.setProductId(productId);
					brand.setUpdateUserId(userId);
					String exeStatus = spbs.saveProductBrand(brand);
					if("SUCCESS".equals(exeStatus)){
						statusCode = "200";
						message = "新增品牌成功!";
					}else{
						statusCode = "300";
						message = "系统繁忙, 新增品牌失败!";
					}
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
			statusCode = "300";
			message = "系统异常, 新增品牌失败!";
		}
		return SUCCESS;
	}
}
